package com.ruoyi.system.service.impl;

import com.github.pagehelper.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TcyPlatformOrder;
import com.ruoyi.system.mapper.TcyPlatformOrderMapper;
import com.ruoyi.system.service.ITcyPlatformOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 平台支付订单Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@Service
public class TcyPlatformOrderServiceImpl implements ITcyPlatformOrderService
{
    @Autowired
    private TcyPlatformOrderMapper tcyPlatformOrderMapper;

    /**
     * 查询，根据外部交易号
     */
    @Override
    public TcyPlatformOrder queryByOutTradeNo(String outTradeNo){

        return tcyPlatformOrderMapper.queryByOutTradeNo(outTradeNo);
    }





    /**
     * 查询待开发票订单（带分页）
     */
    @Override
    public Page<TcyPlatformOrder> findUninvoicedOrdersWithPage(String openid, Page<TcyPlatformOrder> page) {
        // 封装查询参数
        TcyPlatformOrder order = new TcyPlatformOrder();
        order.setOpenId(openid);

        // 执行分页查询
        return tcyPlatformOrderMapper.selectTcyPlatformOrderPage(order, page);
    }

    /**
     * 待开发票订单列表
     *
     * @param openid 用户OpenID
     * @return 平台支付订单
     */
    @Override
    public List<TcyPlatformOrder>  findUninvoicedOrders(String openid)
    {
        return tcyPlatformOrderMapper.findUninvoicedOrders(openid);
    }

    /**
     * 查询平台支付订单
     *
     * @param id 平台支付订单主键
     * @return 平台支付订单
     */
    @Override
    public TcyPlatformOrder selectTcyPlatformOrderById(Long id)
    {
        return tcyPlatformOrderMapper.selectTcyPlatformOrderById(id);
    }

    /**
     * 查询平台支付订单列表
     *
     * @param tcyPlatformOrder 平台支付订单
     * @return 平台支付订单
     */
    @Override
    public List<TcyPlatformOrder> selectTcyPlatformOrderList(TcyPlatformOrder tcyPlatformOrder)
    {
        return tcyPlatformOrderMapper.selectTcyPlatformOrderList(tcyPlatformOrder);
    }

    /**
     * 新增平台支付订单
     *
     * @param tcyPlatformOrder 平台支付订单
     * @return 结果
     */
    @Override
    public int insertTcyPlatformOrder(TcyPlatformOrder tcyPlatformOrder)
    {
        tcyPlatformOrder.setCreateTime(DateUtils.getNowDate());
        return tcyPlatformOrderMapper.insertTcyPlatformOrder(tcyPlatformOrder);
    }

    /**
     * 修改平台支付订单
     *
     * @param tcyPlatformOrder 平台支付订单
     * @return 结果
     */
    @Override
    public int updateTcyPlatformOrder(TcyPlatformOrder tcyPlatformOrder)
    {
        tcyPlatformOrder.setUpdateTime(DateUtils.getNowDate());
        return tcyPlatformOrderMapper.updateTcyPlatformOrder(tcyPlatformOrder);
    }

    /**
     * 修改平台支付订单
     *
     * @param tcyPlatformOrder 平台支付订单
     * @return 结果
     */
    @Override
    public int updateTcyPlatformOrderBy(TcyPlatformOrder tcyPlatformOrder)
    {
        tcyPlatformOrder.setUpdateTime(DateUtils.getNowDate());
        return tcyPlatformOrderMapper.updateTcyPlatformOrderBy(tcyPlatformOrder);
    }

    /**
     * 批量删除平台支付订单
     *
     * @param ids 需要删除的平台支付订单主键
     * @return 结果
     */
    @Override
    public int deleteTcyPlatformOrderByIds(Long[] ids)
    {
        return tcyPlatformOrderMapper.deleteTcyPlatformOrderByIds(ids);
    }

    /**
     * 删除平台支付订单信息
     *
     * @param id 平台支付订单主键
     * @return 结果
     */
    @Override
    public int deleteTcyPlatformOrderById(Long id)
    {
        return tcyPlatformOrderMapper.deleteTcyPlatformOrderById(id);
    }

    @Override
    public int updateKaipiaoStatusByOrderSn(String outTradeNo, int kaipiaoStatus) {
        return tcyPlatformOrderMapper.updateKaipiaoStatusByOrderSn(outTradeNo,kaipiaoStatus);
    }
}
